package com.blog.module.news.service;

import java.util.ArrayList;
import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import com.blog.common.mybatis.Page;
import com.blog.common.mybatis.ParsePagination;
import com.blog.module.news.mapper.NewsMapper;
import com.blog.module.news.pojo.News;
import com.blog.module.news.pojo.NewsExample;
import com.blog.module.news.pojo.NewsExample.Criteria;


/**
 * @Title: NewsService.java
 * @Description: 新闻类别
 * @author user
 * @date 2016年7月28日 下午2:59:36
 * @version V1.0
 */
@Service
public class NewsService {
	
	@Autowired
	private NewsMapper newsMapper;
	
	/**
	 * @Title: newsPageList
	 * @Description: 查询所有新闻类别
	 * @param
	 * @return Page
	 * @throws
	 */	
	public Page newsPageList(News news){
		ParsePagination pagination = new ParsePagination();
		int pageNo = pagination.getPageNo();
		int pageSize = pagination.getPageSize();
		NewsExample example = new NewsExample();
		Criteria criteria= example.createCriteria();
		if(news != null){
			criteria.andTitleEqualTo(news.getTitle());
		}
		int count = newsMapper.countByExample(example);
		List<News> list = new ArrayList<News>();
		Page page = new Page(count, pageNo, pageSize, list);
		example.setLimitStart((pageNo - 1) * pageSize);
		example.setLimitEnd(pageSize);
		list = newsMapper.selectByExample(example);
		page.setList(list);
		return page;
		
	}
	
	public int insert(News news){
		return newsMapper.insert(news);
	}
	public int delete(int id){
		return newsMapper.deleteByPrimaryKey(id);
	}
	public News selectById(int id){
		return newsMapper.selectByPrimaryKey(id);
	}
	
	

}
